package com.shop.cereshop.app.controller.tencent.im;

import com.shop.cereshop.app.tencent.im.model.product.SendProductMsgParam;
import com.shop.cereshop.app.tencent.im.service.ProductMsgService;
import com.shop.cereshop.commons.domain.buyer.CereBuyerUser;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @description: 商品消息Controller
 * @author zdd
 * @date 2025/11/5
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("tim/product")
@Api(value = "商品消息接口", tags = "商品消息接口")
public class ProductMsgController {

  @Resource
  private ProductMsgService productMsgService;

  /**
   * 发送商品消息
   */
  @PostMapping("sendProductMsg")
  @ApiOperation(value = "发送商品消息", notes = "在聊天中分享商品")
  public Result<Void> sendProductMsg(@RequestBody @Validated SendProductMsgParam param, HttpServletRequest request) {
    CereBuyerUser user = (CereBuyerUser) request.getAttribute("user");
    if (user == null) {
      return Result.unauthorized();
    }
    return productMsgService.sendProductMsg(param, user);
  }

}
